<template>
	<view class="supplierDetail">
		<view class="form-wrapper">
			<view class="form-title">
				<view class="title">
					供货状态
				</view>
				<view class="content">
					{{ statusName }}
				</view>
			</view>
		</view>
		<view class="form-wrapper">
			<view class="form-title">
				<view class="title">
					归属总仓
				</view>
			</view>
			<view class="form-content">
				<view class="form-item">
					<text class="label">总仓名称</text>
					<text class="value">{{ form.supplyWarehouseName }}</text>
				</view>
				<view class="form-item">
					<text class="label">运营专员</text>
					<text class="value">{{ form.operationSpecialistName || '-' }}</text>
				</view>
				<view class="form-item">
					<text class="label">电话</text>
					<text class="value">{{ form.operationSpecialistTel || '-' }}</text>
				</view>
			</view>
		</view>
		<view class="form-wrapper">
			<view class="form-title">
				<view class="title">
					经营备案
				</view>
			</view>
			<view class="form-content">
				<view class="form-item">
					<text class="label">主体类型</text>
					<text class="value" v-if="form.subjectType">{{ orgTypeList[form.subjectType - 1] }}</text>
					<text class="value" v-else>-</text>
				</view>
				<view class="form-item">
					<text class="label">供应商名称</text>
					<text class="value">{{ form.supplierName }}</text>
				</view>
				<view class="form-item">
					<text class="label">供应商编号</text>
					<text class="value">{{ form.supplierCode || '-' }}</text>
				</view>
				<view class="form-item">
					<text class="label">管理员</text>
					<text class="value">{{ form.manager || '-' }}</text>
				</view>
				<view class="form-item">
					<text class="label">管理员电话</text>
					<text class="value" @click="callPhone(form.managerTel)">{{ form.managerTel || '-' }}</text>
				</view>
				<view class="form-item">
					<text class="label">客服电话</text>
					<text class="value" @click="callPhone(form.managerTel)">{{ form.serviceTel || '-' }}</text>
				</view>
				<view class="form-item">
					<text class="label">经营地址</text>
					<text class="value">{{ form.businessAddress || '-' }}</text>
				</view>
				<view class="form-item">
					<text class="label">经营类目</text>
					<text class="value">{{ form.businessCategoryName || '-' }}</text>
				</view>
			</view>
		</view>

		<view class="btn-wrapper">
			<view class="btn" @click="goEditCategory">
				修改经营类目
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				form: {},
				orgTypeList: ['自然人', '企业', '个体户'],
			}
		},
		onLoad(option) {
			this.getInfo(option.id)
		},
		computed: {
			statusName() {
				const status = ["注册中", "平台审核中", "银行审核中", "供货中", "暂停供货", "已冻结", "已注销"]
				return status[this.form.supplierStatus]
			}
		},
		methods: {
			async getInfo(id) {
				const data = await this.$api.get('/adm/supplier/getInfo', {
					id: id
				})
				if (data.code === 200) {
					if (data.data.businessCategory) {
						let businessCategory = JSON.parse(data.data.businessCategory).map(item => {
							return item.categoryName
						})
						if (businessCategory.length > 10) {
							businessCategory = businessCategory.slice(0, 10)
							businessCategory.push('等等')
						}
						data.data.businessCategoryName = businessCategory.join()
					}
					this.form = data.data;
				}
			},
			goEditCategory() {
				if (this.form.businessCategory) {
					const businessCategory = JSON.parse(this.form.businessCategory);
					uni.setStorageSync('businessCategory', businessCategory)
				}
				uni.navigateTo({
					url: "/subPage_supplier/register/category?supplierId=" + this.form.id
				})
			},
			callPhone(tel) {
				if (!tel) return
				uni.makePhoneCall({
					phoneNumber: tel
				})
			},
		},
		components: {

		}
	}
</script>

<style lang="scss" scoped>
	.supplierDetail {
		height: 100%;
		overflow: auto;
		padding-bottom: 100upx;
		padding: 0 24upx;

		.form-wrapper {
			background-color: #ffffff;
			border-radius: 20upx;
			margin-top: 20upx;

			.form-title {
				height: 100upx;
				display: flex;
				align-items: center;
				justify-content: space-between;
				padding-right: 30upx;

				.title {
					font-size: 32upx;
					border-left: 8upx solid #555BFF;
					padding-left: 20upx;
					height: 32upx;
					font-weight: bold;
					color: #141414;
				}

				.content {
					color: #3B3B3B;
					font-size: 30upx;
				}
			}

			.form-content {
				padding-bottom: 10upx;

				.form-item {
					display: flex;
					//align-items: center;
					justify-content: space-between;
					padding: 0 30upx;
					margin-bottom: 20upx;

					.label {
						min-width: 180rpx;
						color: #808080;
					}

					.value {
						color: #3B3B3B;
					}
				}
			}
		}

		.btn-wrapper {
			position: fixed;
			height: 100upx;
			width: 100%;
			left: 0;
			bottom: 0;
			background-color: #ffffff;
			display: flex;
			align-items: center;
			z-index: 1;
			box-sizing: border-box;

			.btn {
				display: flex;
				align-items: center;
				justify-content: center;
				flex: 1;
				height: 100%;
				background-color: #555BFF;
				color: #ffffff;

				&.default {
					color: #232323;
					background-color: #ffffff;
				}
			}
		}
	}
</style>